package com.lyloou.practice.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lyloou
 * @date 2020/06/12
 * @desc
 */
@ControllerAdvice
public class DemoExceptionResolver {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String handleException(Exception e) {
        if (e instanceof ArithmeticException) {
            return "ArithmeticException: " + e.getMessage();
        }
        return e.getMessage();
    }
}
